package ejb;

import entities.Product;
import entities.PurchasedProduct;
import entities.TiendaliaOrder;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Jesús
 */
@Stateless
public class PurchasedProductBean implements PurchasedProductBeanLocal {

    @PersistenceContext(unitName = "Tiendalia-ejbPU")
    private EntityManager em;

    @Override
    public List<PurchasedProduct> findAll() {
        Query query = em.createNamedQuery("");
        return query.getResultList();
    }

    @Override
    public List<PurchasedProduct> findByProduct(Product product) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<PurchasedProduct> findByOrder(TiendaliaOrder order) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public PurchasedProduct insert(PurchasedProduct purchasedProduct) {
        return update(purchasedProduct);
    }

    @Override
    public PurchasedProduct update(PurchasedProduct purchasedProduct) {
        return em.merge(purchasedProduct);
    }
}
